package com.jic.market.orm;

import com.jic.market.request.BaseRequest;

import java.io.Serializable;

public class Pagination implements Serializable {
    private static final long serialVersionUID = 2826397969274951545L;
    private int pageNo = 1;
    private int pageSize = 20;
    private int limitStart = 0;
    private String orderBy;

    public Pagination() {
    }

    public int getLimitStart() {
        return this.limitStart;
    }

    public void setLimitStart(int limitStart) {
        this.limitStart = limitStart;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return this.pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public String getOrderBy() {
        return this.orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }


    public static Pagination build(BaseRequest baseRequest) {
        Pagination pagination = new Pagination();
        pagination.setLimitStart((baseRequest.getPageNo() - 1) * baseRequest.getPageSize());
        pagination.setPageSize(baseRequest.getPageSize());
        pagination.setOrderBy(baseRequest.genOrderBys());
        return pagination;
    }

    public static Pagination build(int pageNo, int pageSize, String orderBy) {
        Pagination pagination = new Pagination();
        pagination.setLimitStart((pageNo - 1) * pageSize);
        pagination.setPageSize(pageSize);
        pagination.setOrderBy(orderBy);
        return pagination;
    }
    public static Pagination build(int pageNo, int pageSize) {
        Pagination pagination = new Pagination();
        pagination.setLimitStart((pageNo - 1) * pageSize);
        pagination.setPageSize(pageSize);
        return pagination;
    }
}
